package com.ssu.judea.travlog.view;

import java.util.List;

import com.ssu.judea.travlog.R;
import com.ssu.judea.travlog.util.UrlImageConverter;
import com.ssu.judea.travlog.vo.DatePost;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PostDateListAdapter extends BaseAdapter {
	private List<DatePost> mList;
	private Context mContext;
	private int mLayout;
	
	public PostDateListAdapter(Context context, int layout, List<DatePost> list) {
		mContext = context;
		mLayout = layout;
		mList = list;
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return Long.parseLong(String.valueOf( position ));
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		DatePost mItem = mList.get(position);
		LayoutInflater inflate = LayoutInflater.from(mContext);
		
		View mCurView = inflate.inflate(mLayout, parent, false);
		
		ImageView profile = (ImageView)mCurView.findViewById(R.id.imageProfile);
		TextView screenName = (TextView)mCurView.findViewById(R.id.textScreenName);
		TextView location = (TextView)mCurView.findViewById(R.id.textLocation);
		TextView regdate = (TextView)mCurView.findViewById(R.id.textRegdate);
		TextView count = (TextView)mCurView.findViewById(R.id.textCountPost);
		
		UrlImageConverter converter = new UrlImageConverter();
		profile.setImageDrawable(converter.urlToDrawable(mItem.getImageurl()));
		screenName.setText(mItem.getTwitterid());
		location.setText(mItem.getLatitude()+", "+mItem.getLongitude());
		regdate.setText(mItem.getRegdate());
		count.setText("( "+String.valueOf(mItem.getPostscount())+" Posts )");
		
		return mCurView;
	}

}
